﻿using log4net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PhysicalExamination5.Interface;
using PhysicalExamination5.Interface.DataMaintenance;
using PhysicalExamination5.Model.DataMaintenance;
using PhysicalExamination5.Service.DataMaintenance;
using PhysicalExamination5.WebApi.Utility.JWT;
using System.Security.Claims;

namespace PhysicalExamination5.WebApi.Controllers.DataMaintenance
{
    /// <summary>
    /// 院区维护
    /// </summary>
    [ApiController]
    [ApiVersion("1.0")]
    [Route("[controller]/v{version:apiVersion}")]
    public class YuanQuWeiHuController : Controller
    {
        private readonly IYuanQuWeiHu _IYuanQuWeiHu;
        private static readonly ILog log = LogManager.GetLogger(typeof(YuanQuWeiHuController));
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly ICustomJWTService _ICustomJWTService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="IYuanQuWeiHu"></param>
        /// <param name="ICustomJWTService"></param>
        /// <param name="httpContextAccessor"></param>
        public YuanQuWeiHuController(IYuanQuWeiHu IYuanQuWeiHu, ICustomJWTService ICustomJWTService, IHttpContextAccessor httpContextAccessor)
        {
            _IYuanQuWeiHu = IYuanQuWeiHu;
            _ICustomJWTService = ICustomJWTService;
            _httpContextAccessor = httpContextAccessor;

            //配置日志ip地址参数信息
            string ipAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
            log4net.GlobalContext.Properties["localIpAddress"] = ipAddress;
        }

        /// <summary>
        /// 院区维护添加
        /// </summary>
        /// <param name="YuanQuAddClass"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        [Route("[action]")]
        public IActionResult PostYuanQuAdd(YuanQuAddClass YuanQuAddClass)
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_IYuanQuWeiHu.PostYuanQuAdd(YuanQuAddClass));
        }

        /// <summary>
        /// 院区维护修改
        /// </summary>
        /// <param name="YuanQuUpdateClass"></param>
        /// <returns></returns>
        [HttpPut]
        [Authorize]
        [Route("[action]")]
        public IActionResult PutYuanQuUpdate(YuanQuUpdateClass YuanQuUpdateClass)
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_IYuanQuWeiHu.PutYuanQuUpdate(YuanQuUpdateClass));
        }

        /// <summary>
        /// 院区维护查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        [Route("[action]")]
        public IActionResult GetYuanQuSel()
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_IYuanQuWeiHu.GetYuanQuSel());
        }
    }
}
